﻿using IBLL;
using IDAL;
using Momdel;

namespace BLL
{
    public class BaseBLL:IBaseBLL
    {
        IBaseDAL<UserModel> dal;
        public BaseBLL(IBaseDAL<UserModel> dal)
        {
            this.dal = dal;
        }

        public async Task<dynamic> Loght(string username, string pwd)
        {
            var list= await dal.GetValue(x=>x.Name==username);
            if(list==null)
            {
                return -1;
            }
            else
            {
                if(list.Pwd!=pwd)
                {
                    return -2;
                }
                else
                {
                    return list;
                }
            }

        }

        public IQueryable<UserModel> Query(out int totalcount, out int totalpage, int pagecount = 1, int pagesize = 2)
        {
            var list = dal.GetAll();
            totalcount = list.Count();
            totalpage = (int)Math.Ceiling(totalcount * 1.0 / pagesize);
            list=list.OrderBy(x => x.Id).Skip((pagecount-1)*pagesize).Take(pagesize);
            return list;
        }
    }
}
